package com.sskj.uboex.presenter;

import com.lzy.okgo.request.GetRequest;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.level.bean.TradeListBean;
import com.sskj.lib.http.JsonConverter;
import com.sskj.uboex.bean.KFiveBean;
import com.sskj.uboex.ui.fragment.FiveFragment;

import java.util.List;

import io.reactivex.Flowable;


public class FiveFragmentPresenter extends BasePresenter<FiveFragment> {

    public Flowable<List<TradeListBean>> getData(int page, int pageSize, String code, String type, String tradeType) {
        GetRequest<HttpData<KFiveBean>> tradeList;
        if (type.equals("1")) {
            tradeList = httpService.getTradeEntrustList(page, pageSize, type, code, tradeType);
        } else {
            tradeList = httpService.getTradeNewList(page, pageSize, type, code, tradeType);

        }
        return tradeList.converter(new JsonConverter<HttpData<KFiveBean>>() {
        })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> tradeType.equals("1") ? pageBeanHttpData.getData().getNullOrder().getList() : pageBeanHttpData.getData().getMoreOrder().getList());
    }
}
